﻿Shader "My/BlurShader"
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}
	}

	CGINCLUDE
	#include "UnityCG.cginc"
	static const int maxOffset = 3;
	static const float kernel[7] = {
		0.071303,
		0.131514,
		0.189879,
		0.214607,
		0.189879,
		0.131514,
		0.071303 };

	struct appdata
	{
		float4 vertex : POSITION;
		float2 uv : TEXCOORD0;
	};

	struct v2f
	{
		float2 uv : TEXCOORD0;
		float4 vertex : SV_POSITION;
	};

	sampler2D _MainTex;
	float4 _MainTex_TexelSize;

	v2f vert(appdata v)
	{
		v2f o;
		o.vertex = UnityObjectToClipPos(v.vertex);
		o.uv = v.uv;
		return o;
	}
	ENDCG

    SubShader
    {
        Pass
        {
			Name "Horizontal"
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            fixed4 frag (v2f i) : SV_Target
            {
				fixed4 col = fixed4(0,0,0,0);
				for (int j = -maxOffset; j <= maxOffset; j++) 
				{
					col += tex2D(_MainTex, i.uv + float2(_MainTex_TexelSize.x * j, 0)) * kernel[j + maxOffset];
				}
				return col;
            }
            ENDCG
        }
   
		Pass
		{
			Name "Vertical"
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			fixed4 frag(v2f i) : SV_Target
			{
				fixed4 col = fixed4(0, 0, 0, 0);
				for (int j = -maxOffset; j <= maxOffset; j++) {
					col += tex2D(_MainTex, i.uv + float2(0, _MainTex_TexelSize.y * j)) * kernel[j + maxOffset];
				}
				return col;
			}
			ENDCG
		}
	}
}
